package com.kedou.sdk.download;

import android.app.DownloadManager;
import android.database.Cursor;

public final class DownloadInfo {

    int downloadedBytes = -1;

    int downloadTotalBytes = -1;

    int downloadStatus = -1;

    private DownloadInfo() {
    }

    public static DownloadInfo queryDownloadInfo(DownloadManager downloadManager,  long downloadId) {
        DownloadInfo downloadInfo = new DownloadInfo();

        DownloadManager.Query query = new DownloadManager.Query().setFilterById(downloadId);
        Cursor cursor = null;
        try {
            cursor = downloadManager.query(query);
            if (cursor != null && cursor.moveToFirst()) {
                downloadInfo.downloadedBytes = cursor.getInt(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR));
                downloadInfo.downloadTotalBytes = cursor.getInt(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_TOTAL_SIZE_BYTES));
                downloadInfo.downloadStatus = cursor.getInt(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_STATUS));
            }
        } finally {
            if (cursor != null) {
                cursor.close();
            }
        }

        return downloadInfo;

    }
}
